%% Panel VAR
% by Jaromir Benes
%
% This tutorial explains the basics of panel VAR estimation and simulation
% in IRIS. It only highlights the differences between plain VARs and panel
% VARs, and methods of comparing the two. For more on using plain VARs, see
% other tutorials.

%% How to Best Run This Tutorial?
%
% Each m-file in this tutorial is split into what is called "code sections"
% in Matlab. A code cell is a shorter block of code performing a specific
% task, separated from other code cells by a double percent sign, `%%`
% (usually with a title and brief introduction added). By default, the
% cells are visually separated from each other by a horizontal rule in the
% Matlab editor.
%
% Instead of running each m-file from the command window, or executing this
% `read_me_first` as a whole, do the following. Open one tutorial m-file in
% the Matlab editor. Arrange the editor window and the command window next
% to each other so that you can see both of them at the same time. Then run
% the m-file cell by cell. This will help you watch closely what exactly
% is going on.
%
% To execute one particular cell, place the cursor in that cell (the
% respective block of code will get highlighted), and select "Run Current
% Section" from a contextual menu (upon a right click on the mouse), or
% pressing a keyboard shortcut (which differ on different systems and
% Matlab versions). To learn more on code sections, search Matlab
% documentation for "code section".

%% Read Input Data from CSV Data Files
%
% Prepare a three-country database (Australia, Canada, Norway) that will be
% later used to estimate VAR models.

% edit read_data.m;
read_data;

%% Estimate Plain VARs for Individual Countries
% 
% Estimate three plain VARs for the individual countries. Store and save
% the estimated VAR objects as well as the VAR output data containing the
% estimated residuals.

% edit estimate_individual_countries.m;
estimate_individual_countries;

%% Estimate Panel VAR
% 
% Estimate a panel VAR combining the data for all three countries with
% fixed effect (i.e. dummy constats for each country).

% edit estimate_panel_var.m;
estimate_panel_var;

%% Compare Plain VARs and Panel VARs
% 
% Compare a number of reduced-form and structural properties of the VARs
% estimated on individual countries, and the VAR estimated on a panel of
% data. Show the eigenvalues, the implied unconditional cross-correlation
% coefficients, estimated residuals, and impulse responses from structural
% VARs (using a simple Cholesky identification scheme).

% edit compare_vars_and_pvar.m;
compare_vars_and_pvar;

%% Simulate Plain VARs and Panel VAR
% 
% Simulate the historical data for all three countries from a certain point
% in the past using both the VARs estimated on individual countries and the
% panel VAR.

% edit simulate_vars_and_pvar.m;
simulate_vars_and_pvar;

%% Publish Tutorial Files to PDFs
%
% The following commands can be used to create PDF versions of the tutorial
% files:

%{
    latex.publish('read_me_first.m',[],'evalCode=',false);
    latex.publish('read_data.m');
    latex.publish('estimate_individual_countries.m');
    latex.publish('estimate_panel_var.m');
    latex.publish('compare_vars_and_pvar.m');
    latex.publish('simulate_vars_and_pvar.m');
%}
